From 9712c697a910360c499f2bddbdb510962d17be8b Mon Sep 17 00:00:00 2001
From: Fuwn <contact@fuwn.me>
Date: Sat, 28 Sep 2024 18:53:43 -0700
Subject: feat(user): move profile page badges to graphql

---
 src/routes/user/[user]/+page.svelte | 29 +++++++++++++----------------
 1 file changed, 13 insertions(+), 16 deletions(-)

(limited to 'src/routes/user/[user]/+page.svelte')

diff --git a/src/routes/user/[user]/+page.svelte b/src/routes/user/[user]/+page.svelte
index 44e50df7..0369a920 100644
--- a/src/routes/user/[user]/+page.svelte
+++ b/src/routes/user/[user]/+page.svelte
@@ -2,7 +2,7 @@
 	import settings from '$stores/settings';
 	import ParallaxImage from '../../../lib/Image/ParallaxImage.svelte';
 	import { typeSchedule, type ParseResult } from '$lib/Hololive/hololive';
-	import { user, type User } from '$lib/Data/AniList/user';
+	import { type User } from '$lib/Data/AniList/user';
 	import HeadTitle from '$lib/Home/HeadTitle.svelte';
 	import Message from '$lib/Loading/Message.svelte';
 	import { estimatedDayReading } from '$lib/Media/Manga/time';
@@ -38,12 +38,9 @@
 				username
 			}
 		}).user.profile.badges;
+	$: ({ Profile } = data);
 
-	onMount(() => {
-		user(data.username, /^\d+$/.test(data.username))
-			.then((profile) => (userData = profile))
-			.catch(() => (error = true));
-	});
+	onMount(() => (userData = data.userData));
 
 	const handleDragStart = (
 		event: DragEvent & { currentTarget: EventTarget & HTMLDivElement },
@@ -252,19 +249,19 @@
 							<p />
 						{/if}
 
-						{#await fetch(root(`/api/badges?id=${userData.id}`))}
+						{#if $Profile.fetching}
 							{displayBadges(userData.name, '...')}
-						{:then badges}
-							{#await badges.json()}
-								{displayBadges(userData.name, '...')}
-							{:then badges}
-								{displayBadges(userData.name, badges.length)}
-							{:catch}
+						{:else if $Profile.data}
+							{@const badges = $Profile.data.User.badges.length}
+
+							{#if badges}
+								{displayBadges(userData.name, badges)}
+							{:else}
 								{displayBadges(userData.name, '?')}
-							{/await}
-						{:catch}
+							{/if}
+						{:else}
 							{displayBadges(userData.name, '?')}
-						{/await}
+						{/if}
 					</div>
 				</div>
 			</div>
-- 
cgit v1.2.3

